#include <iostream>
#include <vector>
#include <climits>
using namespace std;


int func(const vector<int>& vec)
{
    vector<int> dp(vec.size() + 1,0);
    dp[0] = vec[0] >= 0 ? vec[0] : 0;
    
    for(int i = 1;i < vec.size();i++)
    {
        dp[i] = vec[i] + dp[i - 1];
        if(dp[i] <= 0)
        {
            dp[i] = 0;
        }
    }
    int max = INT_MIN;
    for(auto i : dp)
    {
        if(i > max)
        {
            max = i;
        }
    }
    return max;
}
int main()
{
    //给定一个数组，找出数组元素中最大的子段和
    vector<int> vec = {-2,-8,11,-4,13,-5,-2};
    int sumResult = func(vec);
    cout << sumResult << endl;
}